package com.heima.wemedia.controller;

import com.heima.common.dtos.PageResult;
import com.heima.common.dtos.ResponseResult;
import com.heima.model.media.dtos.WmNewsDto;
import com.heima.model.media.dtos.WmNewsPageReqDto;
import com.heima.model.media.dtos.WmNewsResultDTO;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {

    @Autowired
    private WmNewsService wmNewsService;

    //分页查询文章
    @PostMapping("/page")
    public PageResult<WmNewsDto> findByPage(@RequestBody WmNewsPageReqDto dto){
        return wmNewsService.findByPage(dto);
    }


    //新增、修改、发布自媒体文章
    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDto dto){
        return wmNewsService.submit(dto);
    }

    //根据id查询自媒体文章
    @GetMapping("/one/{id}")
    public ResponseResult<WmNewsResultDTO> findById(@PathVariable Integer id){
        return wmNewsService.findById(id);
    }
}
